import {HvigorNode, HvigorPlugin} from '@ohos/hvigor';
import {DeleteAppTaskConfig, deleteExcessAppFileTask} from "./task/DeleteAppTask";
import {deleteBuildTask, DeleteBuildTaskConfig} from "./task/DeleteBuildTask";

export function deleteExcessAppFilePlugin(config?: DeleteAppTaskConfig): HvigorPlugin {
    const id = "deleteExcessAppFilePlugin"
    return {
        pluginId: id,
        apply(node: HvigorNode) {
            /*node.subNodes((node: HvigorNode) => {
            })*/
            const startTime = new Date().getTime()
            deleteExcessAppFileTask(config)
            console.info(id + " after " + (new Date().getTime() - startTime) + " ms")
        }
    }
}

// 实现自定义插件
export function deleteBuildPlugin(config?: DeleteBuildTaskConfig): HvigorPlugin {
    const id = "deleteBuildPlugin"
    return {
        pluginId: id,
        apply(node: HvigorNode) {
            /* node.subNodes((node: HvigorNode) => {
             })*/
            const startTime = new Date().getTime()
            deleteBuildTask(node.getNodePath(), config)
            console.info(id + " after " + (new Date().getTime() - startTime) + " ms")
        }
    }
}
